<template>
	<view class="mainbgc">
		<header-top :messageInfo="{typeFlag:true,message:'拜访任务',liner:false}">
			<view class="rightmsg" slot="rightmsg">
				<view class="rightmsg_content flexleft">
					<view class="add" @click="jumpurl('/pages/homepage/news/renwu',54)"></view>
				</view>
			</view>
		</header-top>
		<!-- 按任务 -->
		<view class="anrenwu">
			<!-- <view class="margin_top strongtext flexbetween">
				<view>共计：{{list.total_custom_num}}个</view>
				<view>
					已拜访：<text class="margin_right labletext2">{{list.visit_num}}</text>
					未拜访：<text class="margin_right labletext1">{{list.no_visit_num}}</text>
				</view>
			</view> -->
			<view class="">
				<!-- 自建任务 -->
				<view class="flexcenter" v-if="!list.data.length">
					<view class="placeholderimage"></view>
				</view>
				<view class="margin_top ffffff radius" v-for="(item,index) in list.data" :key="item.id">
					<uni-swipe-action-item :right-options="options" :auto-close="false"
						@click.stop="onClickrw($event,item.id,index,56)">
						<u-collapse accordion :border="false" :clickable="false">
							<u-collapse-item>
								<!-- 自建任务 -->
								<view slot="title" class="u-page__item__title__slot-title ffffff radius">
									<view class="flexleft">
										<view :class="item.type==1?'persontask margin_right':'bosstask margin_right'">
										</view>
										<view class="titletext">{{item.title}}</view>
									</view>
									<view class="margin_top jzsj">时间：{{item.start_time_text}} 至 {{item.end_time_text}}
									</view>
								</view>
								<view class="" v-for="ite in item.custom" :key="ite.id">
									<view class="line"></view>
									<view class="ffffff selectpadding itembox" @click="bfCustome(ite.id)">
										<!-- 0=未拜访,10=正在拜访,20=拜访完成 -->
										<view class="wlable flexcenter" v-if="ite.visit_status==0">未拜访</view>
										<view class="ylable flexcenter" v-if="ite.visit_status==10">拜访中</view>
										<view class="ylable flexcenter" v-if="ite.visit_status==20">已完成</view>
										<view class="flexleft">
											<!-- 老板or个人 -->
											<view class="persontask margin_right" v-show="item.type==1"></view>
											<view class="bosstask margin_right" v-show="item.type==2"></view>
											<view class="titletext">{{ite.name}}</view>
											<view class="grade">{{ite.customlevel.name}}</view>
										</view>
										<view class="flexbetween margin_top">
											<view class="smalltext">姓名：{{ite.username}}
											<view class="flexleft margin_top">
												<view class="smalltext xiankuan">地址：{{ite.cityinfo}}{{ite.address}}
												</view>
											</view>
											<view class="margin_top flexleft">
												<view class="smalltext">经办人：{{item.staff.username}}</view>
												<view class="dizhiimg" @click.stop="phone(item.staff.mobile)">
												</view>
											</view>
										</view>
										<view class="flexright">
											<view class="addressicon margin_right" style="width: 70rpx;height: 70rpx;"
												@click.stop="openmap(ite)">
											</view>
											<view class="phoneicon" style="width: 70rpx;height: 70rpx;"
												@click.stop="phone(ite.mobile)"></view>
										</view>
									</view>
								</view>
								<view class="margin_top flexbetween nobottom">
									<view class="nocaigou">
										<text style="font-size: 22rpx;">未采购天数：<text
												class="redtext">{{ite.no_sale_days}}天</text></text>
									</view>
									<view class="nobaifang">
										<text style="font-size: 22rpx;">未拜访天数：<text
												class="redtext">{{ite.no_visit_days}}天</text></text>
									</view>
								</view>
				</view>
				</u-collapse-item>
				</u-collapse>

				</uni-swipe-action-item>

			</view>
			<!-- 老板任务 -->
			<!-- <view class="margin_top ffffff radius">
					<u-collapse accordion :border="false">
						<u-collapse-item>
							<view slot="title" class="u-page__item__title__slot-title flexleft ffffff radius">
								<view class="lbbox flexcolumn margin_right">
									<view class="lefttime">07月</view>
									<view class="lefttime">08日</view>
								</view>
								<view>
									<view class="bosstask margin_right"></view>
									<view class="margin_top jzsj">时间：06-07 00:00 至 06-07 23:59</view>
								</view>
							</view>
							<view class="" v-for="item in 5">
								<view class="line"></view>
								<view class="ffffff selectpadding itembox">
									<view class="ylable flexcenter">已拜访</view>
									<view class="flexleft">
										<view class="bosstask margin_right"></view>
										<view class="titletext">隆发服饰商行</view>
										<view class="grade">1级</view>
									</view>
									<view class="flexbetween margin_top">
										<view class="">
											<view class="flexbetween">
												<view class="flexleft">
													<view class="smalltext">姓名：张照中 距上次拜访 <text class="redtext">8</text>天
													</view>
												</view>
											</view>
											<view class="flexleft margin_top">
												<view class="smalltext xiankuan">地址：郑州市金水区农业路莲花街北门</view>
												<view class="addresstext">299km</view>
											</view>
										</view>
										<view class="flexright">
											<view class="addressicon margin_right" style="width: 70rpx;height: 70rpx;">
											</view>
											<view class="phoneicon" style="width: 70rpx;height: 70rpx;"></view>
										</view>
									</view>
								</view>
								<view class="flexbetween nobottom">
									<view class="nocaigou">
										<text style="font-size: 22rpx;">未采购天数：<text class="redtext">28</text>天</text>
									</view>
									<view class="nobaifang">
										<text style="font-size: 22rpx;">未拜访天数：<text class="redtext">88</text>天</text>
									</view>
								</view>
							</view>
						</u-collapse-item>
					</u-collapse>
				</view> -->
		</view>
	</view>

	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#dd524d'
					}
				}],
				current: 1,
				botcurrent: 2,
				page: 1,
				limit: 12,
				list: {
					data: []
				},

			}
		},
		onShow() {
			this.init()
		},
		methods: {
			getinfo() {
				httpRequest.request('appapi/manage/user/info', 'POST', {}, false, false, true).then(res => {
					if (res.code == 1) {
						this.ywyname = res.data.user_info.name
					}
				})
			},

			bfCustome(id) {
				uni.navigateTo({
					url: "/pages/workbench/xiaoshou/baifangmd?id=" + id
				})
			},
			init(isPage, page) {
				let _this = this;
				httpRequest.request('/dhtapi/Custom/visitRwList', 'POST', {
					page: page || 1,
					limit: _this.limit,
				}, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							_this.list = resList
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			// 右滑删除任务(单个)
			onClickrw(e, id, value,qxpdid) {
				if (!httpRequest.qxpd(qxpdid, this.$store.state.userInfo.ability_rule_ids)) {
					return false
				}
				httpRequest.request('/dhtapi/Custom/deleteVisitRw', 'POST', {
					id: id
				}, false, false, true).then(res => {
					httpRequest.toast(res.msg);
					if (res.code == 1) {
						this.list.data.splice(value, 1)
					}
				}).catch(err => {
					httpRequest.toast(res.msg);
				})
			},
			// 打开地图
			openmap(item) {
				uni.openLocation({
					latitude: Number(item.latitude), //即将传到高德或腾讯地图的终点纬度  必须是数值，字符串无效
					longitude: Number(item.longitude), //即将传到高德或腾讯地图的终点经度  必须是数值，字符串无效
					name: item.address, //即将传到高德或腾讯地图的店铺名称
					address: item.address, //即将传到高德或腾讯地图的详细地址
				})
			},
			phone(p) {
				uni.makePhoneCall({
					phoneNumber: p.toString()
				}).catch((e) => {
					// console.log(e)  //用catch(e)来捕获错误{makePhoneCall:fail cancel}
				})
			},
			// 米，公里转换
			kmUnit(m) {
				var v;
				if (typeof m === 'number' && !isNaN(m)) {
					if (m >= 1000) {
						v = (m / 1000).toFixed(2) + 'km'
					} else {
						v = m + 'm'
					}
				} else {
					v = '0m'
				}
				return v;
			},
			// 添加任务
			jumpurl(url,qxpdid) {
				if (!httpRequest.qxpd(qxpdid, this.$store.state.userInfo.ability_rule_ids)) {
					return false
				}
				uni.navigateTo({
					url: url
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	// tab切换
	.tabs {
		padding: 30rpx 84rpx;
	}

	.focustext {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #0BBDCB;
	}

	.nofocustext {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #000;
	}

	.fenge {
		width: 1rpx;
		height: 28rpx;
		background-color: #f5f5f5;
	}

	// 内容
	.itembox {
		position: relative;
	}

	.nobottom {
		padding: 20rpx 30rpx;
		background-color: #F1F1F1;
		border-radius: 10rpx;
	}

	// lable
	// 未拜访
	.wlable {
		background-color: #fef7ec;
		position: absolute;
		right: 0;
		top: 0;
		padding: 10rpx 30rpx;
		font-size: 20rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #F3AD3D;
		line-height: 23rpx;
		border-bottom-left-radius: 20rpx;
		border-top-right-radius: 20rpx;
	}

	// 已拜访
	.ylable {
		background-color: #e6f8ee;
		position: absolute;
		right: 0;
		top: 0;
		padding: 10rpx 30rpx;
		font-size: 20rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #00b855;
		line-height: 23rpx;
		border-bottom-left-radius: 20rpx;
		border-top-right-radius: 20rpx;
	}

	.grade {
		color: #FF0000;
		font-size: 32rpx;
		margin-left: 40rpx;
	}

	.gradetwo {
		color: #FF6B00;
	}

	.gradethree {
		color: #00B855;
	}

	.gradefour {
		color: #0075FF;
	}

	.margin_right {
		margin-right: 30rpx;
	}

	.smalltext {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #737373;
	}

	.xiankuan {
		width: 300rpx;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	// 按任务
	.anrenwu {
		padding: 0 30rpx 156rpx 30rpx;
	}

	.zjbox {
		background-color: #F3AD3D;
		width: 90rpx;
		height: 90rpx;
		border-radius: 50%;
	}

	.lbbox {
		background-color: #0BBDCB;
		width: 90rpx;
		height: 90rpx;
		border-radius: 50%;
	}

	.lefttime {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		line-height: 28rpx
	}

	.jzsj {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #737373;
	}

	.line {
		height: 1rpx;
		margin-bottom: 10rpx;
		width: 100%;
		background-color: #f6f6f6;
	}

	.selectpadding {
		padding: 30rpx 0;
	}

	// 底部tab
	.tab_bottom {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		box-sizing: border-box;
		padding: 30rpx 30rpx 50rpx 30rpx;
	}

	.tab1 {
		border: 2rpx solid #0BBDCB;
		border-right: none;
		border-top-left-radius: 50rpx;
		border-bottom-left-radius: 50rpx;
		padding: 12rpx 50rpx;
	}

	.tab2 {
		border: 2rpx solid #0BBDCB;
		padding: 12rpx 50rpx;
	}

	.tab3 {
		border: 2rpx solid #0BBDCB;
		border-left: none;
		border-top-right-radius: 50rpx;
		border-bottom-right-radius: 50rpx;
		padding: 12rpx 50rpx;
	}

	// 选中的底部
	.selecbottab {
		background-color: #0BBDCB;
		color: #FFFFFF;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
	}

	// 未选中的底部
	.noselecbottab {
		background-color: #fff;
		color: #0BBDCB;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
	}

	.labletext1 {
		color: #ff0000;
	}

	.labletext2 {
		color: #ffa126;
	}
</style>